package com.htrq.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.text.ParseException;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.htrq.entity.ICKcz;
import com.htrq.entity.Page;
import com.htrq.entity.TotalMoney;
import com.htrq.service.ICardczService;
import com.htrq.util.ExportToExcelUtil;

@Controller
@RequestMapping("jsp/basinfo")
public class ICardczController {
	@Resource
	private ICardczService czService;

	@RequestMapping("getAllkcz")
	public String getAllkcz(ICKcz kcz,Page page ,HttpServletResponse response) throws IOException, ParseException {
		List<ICKcz> list=czService.getAllkcz(kcz,page);
		String str = JSON.toJSONString(list);
		Long count=czService.getTotal(kcz);
		String json = "{total:" + count + ",kczs:" + str + "}";
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(json);
		return null;
	}
	
	@RequestMapping("getTotalkczmoney")
	public String getTotalkczmoney(ICKcz kcz,HttpServletResponse response) throws IOException{
		TotalMoney tota=czService.getMoneyandNum(kcz);
		String str = JSON.toJSONString(tota);
		response.setContentType("text/html;charset=utf8");
		PrintWriter out = response.getWriter();
		out.print(str);
		return null;
	}
	
	@RequestMapping("exportcz")
	public String export(ICKcz kcz,HttpServletRequest request,HttpServletResponse response) throws Exception{
		String titles[]={"卡号","卡类型","持卡人","客户单位","车号","操作类型","充值前金额","充值金额","优惠金额","充值后金额","充值日期","充值站点","操作员"};
		List<Object[]> list=czService.exportbyForm(kcz);
		ExportToExcelUtil.exportToExcel(request,response,"卡充值查询导出结果.xls", "卡数据", titles, list);
		return null;
	}
}
